package de.zainodis.triplog.ui;

import android.content.Context;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import de.zainodis.triplog.R;
import de.zainodis.triplog.data.WeatherEntry;
import de.zainodis.triplog.ui.fragment.ForecastFragment;
import de.zainodis.triplog.ui.task.CompletedTripsLoader;
import de.zainodis.triplog.util.DateTimeUtils;
import de.zainodis.triplog.util.Utilities;

/**
 * Created by fzarrai on 1/25/2015.
 * Handles the display of a list of completed trips.
 */
public class TripListAdapter extends CursorAdapter {

    private static final String TAG = "TripListAdapter";

    public TripListAdapter(Context context, Cursor cursor, int flags) {
        super(context, cursor, flags);
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        int viewType = getItemViewType(cursor.getPosition());
        int layoutId = R.layout.list_item_tripentry;
        View view = LayoutInflater.from(context).inflate(layoutId, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setTag(viewHolder);
        return view;
    }


    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        ViewHolder viewHolder = (ViewHolder) view.getTag();

        int tripId = cursor.getInt(CompletedTripsLoader.COLUMN_ID);
        String start = cursor.getString(CompletedTripsLoader.COLUMN_DATE_START);
        String end = cursor.getString(CompletedTripsLoader.COLUMN_DATE_END);

        //TODO continue implementing the view for each trip entry

    }

    private static class ViewHolder {
        public final ImageView photo;
        public final TextView destination;
        public final TextView duration;

        public ViewHolder(View view) {
            photo = (ImageView) view.findViewById(R.id.list_item_tripentry_image);
            destination = (TextView) view.findViewById(R.id.list_item_tripentry_destination);
            duration = (TextView) view.findViewById(R.id.list_item_tripentry_duration);
        }
    }
}
